1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use biodivine_lib_param_bn::BinaryOp as OtherBinaryOp;
use core::convert::From;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Error, Formatter};

/// Enum for all possible Boolean binary operators occurring in update functions
/// or first-order formulas (for static properties).
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, PartialOrd)]
pub enum BinaryOp {
    And, // '&'
    Or,  // '|'
    Xor, // '^'
    Imp, // '=>'
    Iff, // '<=>'
}

impl From<OtherBinaryOp> for BinaryOp {
    fn from(value: OtherBinaryOp) -> Self {
        match value {
            OtherBinaryOp::And => BinaryOp::And,
            OtherBinaryOp::Or => BinaryOp::Or,
            OtherBinaryOp::Xor => BinaryOp::Xor,
            OtherBinaryOp::Iff => BinaryOp::Iff,
            OtherBinaryOp::Imp => BinaryOp::Imp,
        }
    }
}

impl Display for BinaryOp {
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
        let symbol = match self {
            BinaryOp::And => "&",
            BinaryOp::Or => "|",
            BinaryOp::Xor => "^",
            BinaryOp::Imp => "=>",
            BinaryOp::Iff => "<=>",
        };
        write!(f, "{}", symbol)
    }
}

impl BinaryOp {
    pub fn to_lib_param_bn_version(&self) -> OtherBinaryOp {
        match self {
            BinaryOp::And => OtherBinaryOp::And,
            BinaryOp::Or => OtherBinaryOp::Or,
            BinaryOp::Xor => OtherBinaryOp::Xor,
            BinaryOp::Iff => OtherBinaryOp::Iff,
            BinaryOp::Imp => OtherBinaryOp::Imp,
        }
    }
}